<?php

namespace Cmd\user;

use Wechat\Config;

class help
{
    /**
     * 帮助命令入口
     *
     * @param [type] $message
     * @return void
     */
    public function help($message, $openid)
    {
        $role = '';
        $allowCmd = [];
        $param_cmd = '';
        if ($message) { // 角色命令查询
            if (Config::cmdAuth($message, $openid)) {
                $role = $message;
            }
        }
        $role = $role ? $role : 'user';
        if (!$allowCmd = Config::cmdAllow([$role])) {
            return '暂无【' . $role . '】帮助手册';
        }
        $cmd = '';
        $cmd = "          【help命令帮助】\n\n";
        foreach ($allowCmd as $k => $v) {
            $param_cmd .= "命令：{$k}" . ($k == 'text' ? ' (默认)' : '') . "\n";
            if (is_array($v['short']) && $v['short']) {
                $param_cmd .= "缩写：";
                foreach ($v['short'] as $key => $val) {
                    $param_cmd .= "{$val}、";
                }
                $param_cmd = rtrim($param_cmd, '、') . "\n";
            } else if (is_string($v['short']) && $v['short']) {
                $param_cmd .= "缩写：{$v['short']}\n";
            }
            if ($v['value']) {
                $param_cmd .= "用法：命令@{$v['value']}\n";
            } else {
                $param_cmd .= "用法：回复命令\n";
            }
            $param_cmd .= "介绍：{$v['title']}\n        {$v['description']}\n";
            $param_cmd .= str_repeat("-", 35) . "\n";
        }
        $cmd .= str_repeat("-", 35) . "\n";
        $cmd .= $param_cmd . "          【基本用法】\n";
        $cmd .= " 命令    分隔符        参数\n";
        $cmd .= "  dy        @       douyin.com\n";
        $cmd .= str_repeat("-", 35) . "\n";
        $cmd .= "           <a href='https://mp.weixin.qq.com/mp/homepage?__biz=MzU2Njc4NjI0NA==&hid=1&sn=8f907ed9a66c40c29fcb963a77a95e79'>详细帮助手册 >></a>";
        return $cmd;
    }
}
